
INCLUDE(CheckIncludeFiles)

CHECK_INCLUDE_FILES(inttypes.h HAVE_INTTYPES_H)


FUNCTION(FORTRANIZE infile outfile)
  SET(RESULT "")
  FILE(STRINGS "${infile}" lines)
  FOREACH(i IN LISTS lines)
    STRING(REGEX REPLACE "/\\*.*\\*/" "" i "${i}")
    IF(i)
      SET(RESULT "${RESULT}${i}\n")
    ENDIF(i)
  ENDFOREACH()
  FILE(WRITE "${outfile}" "${RESULT}")
ENDFUNCTION(FORTRANIZE infile outfile)

#TODO: is this proper way of choosing shared library API?
IF(WIN32)
  UNSET(HAVE_DLOPEN_API)
  SET(HAVE_LOADLIBRARY_API TRUE)
ELSEIF(UNIX)
  SET(HAVE_DLOPEN_API TRUE)
  SET(HAVE_DLSYM TRUE)
ENDIF()

#STRING(COMPARE EQUAL ${FortranCInterface_GLOBAL_CASE} "LOWER" FC_LINK_CASE)
#STRING(COMPARE EQUAL ${FortranCInterface_GLOBAL_SUFFIX} "" FC_LINK_SUFFIX)
#IF(FC_LINK_CASE)
#  IF(FC_LINK_SUFFIX)
#    SET(ELMER_LINKTYP 3)
#  ELSE()
#    SET(ELMER_LINKTYP 1)
#  ENDIF()
#ELSE()
#  SET(ELMER_LINKTYP 2)
#ENDIF()

#FIND_FILE(FEM_LICENSES LICENSES PATHS ${CMAKE_CURRENT_SOURCE_DIR} NO_DEFAULT_PATH)
#MARK_AS_ADVANCED(FEM_LICENSES)
#INSTALL(FILES ${FEM_LICENSES} DESTINATION "share/elmersolver/license_texts/fem")
INSTALL(FILES "LICENSES" DESTINATION "share/elmersolver/license_texts/fem")
#MARK_AS_ADVANCED(FEM_LICENSES)

INCLUDE(CheckTypeSize)
CHECK_TYPE_SIZE(long LONG_SIZE)
IF(LONG_SIZE EQUAL 4)
  SET(OFF_KIND "selected_int_kind(9)")
ELSEIF(LONG_SIZE EQUAL 8)
  SET(OFF_KIND "selected_int_kind(18)")
ENDIF()

#SET(FC_CHAR_PTR "(P,L) char *P, int L")
SET(ELMER_SOLVER_HOME "${CMAKE_INSTALL_PREFIX}/share/elmersolver" CACHE PATH "")

SET(SHL_EXTENSION ".so")
IF(WIN32)
  SET(SHL_EXTENSION ".dll")
ENDIF()
IF(APPLE)
  SET(SHL_EXTENSION ".dylib")
ENDIF()

CONFIGURE_FILE(config.h.cmake config.h.commented)
FORTRANIZE(${CMAKE_BINARY_DIR}/fem/config.h.commented ${CMAKE_BINARY_DIR}/fem/config.h)

INCLUDE_DIRECTORIES("${PROJECT_BINARY_DIR}")
ADD_SUBDIRECTORY(src)
ADD_SUBDIRECTORY(tests)
